﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Globalization;

namespace BSU.GraduateWork.Web.Routes
{
    public class DimensionRouteConstraint: IRouteConstraint
    {
            #region IRouteConstraint Members

            public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
            {
                if ((routeDirection == RouteDirection.IncomingRequest) && (parameterName.ToLower(CultureInfo.InvariantCulture) == "dimension"))
                {
                    try
                    {
                        string dimension = Convert.ToString(values["dimension"]);
                        if (dimension.Equals("3D", StringComparison.InvariantCultureIgnoreCase) ||
                            dimension.Equals("2D", StringComparison.InvariantCultureIgnoreCase))
                            return true;
                    }
                    catch
                    {
                        return false;
                    }
                }
                return false;
            }

            #endregion
    }
}